<?php

require_once APPPATH."/controllers/BasePriv.php";
require_once APPPATH."/libraries/Tools.php";
use Aws\S3\S3Client;
class Name extends BasePriv
{
    public function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form', "url"));
        $this->load->model("Host_person_model", "table");
    }

    public function index(){
        //分页
        $arr=[];
        $arr['page']=intval($this->get('page'))>0 ? intval($this->get('page')) : 1;
        $arr['limit']=intval($this->get('limit'))>0 ? intval($this->get('limit')) : 10;
        //审核状态筛选
        if(!empty($_GET['online'])){
            $arr['online']=$_GET['online'];
        }
        //关键字搜索
        if(!empty($_GET['keyword'])){
            $arr['keyword']=$_GET['keyword'];
        }
        //时间搜索
        if(!empty($_GET['time'])) {
            $get_time=$this->getStartAndEndTime("get");
            $start_time=strtotime($get_time[0]);
            $end_times=strtotime($get_time[1]);
            $end_time=$end_times+86400;
            $start=date("Y-m-d H:i:s",$start_time);
            $end=date("Y-m-d H:i:s",$end_time);
            $arr['start_time'] =$start;
            $arr['end_time'] =$end;
        }
//        var_dump($arr);exit;

        //查询数据（原始素材）
        $res=$this->table->all($arr);
        //把数据带入视图
        $data['data']=$res;
        $data['page']=$arr['page'];
        $data['limit']=$arr['limit'];
        $this->layout("person/index",$data);
    }

    /**
     * 通过
     */
    public function pass(){
        $id=$_POST['video_uuid'];
        if(empty($id)){
            response(-1,"参数错误");
        }
        $res=$this->table->one("users",['user_id'=>$id]);
        $data['is_status']=3;
        $data['test_user_autograph']=$res['user_autograph'];
        $data['update_time']=date("Y-m-d H:i:s",time());
        $res1=$this->table->update("users",$data,["user_id"=>$id]);
        if($res1){
            response(0,"通过成功");
        }else{
            response(-1,"通过失败");
        }
    }

    /**
     * 不通过
     */
    public function no_pass(){
        $id=$_POST['video_uuid'];
        if(empty($id)){
            response(-1,"参数错误");
        }
        $data['test_user_autograph']="";
        $data['is_status']=1;
        $data['update_time']=date("Y-m-d H:i:s",time());
        $res1=$this->table->update("users",$data,["user_id"=>$id]);
        if($res1){
            response(0,"不通过成功");
        }else{
            response(-1,"不通过失败");
        }
    }

    /**
     * 批量通过
     */
    public function pass_all(){
        $ids=$_POST['ids'];
        if(empty($ids)){
            response(-1,"请选择要批量操作的数据");
        }
        foreach ($ids as $k=>$v){
            $res=$this->table->one("users",['user_id'=>$v]);
            $data['test_user_autograph']=$res['user_autograph'];
            $data['is_status']=3;
            $data['update_time']=date("Y-m-d H:i:s",time());
            $res1=$this->table->update("users",$data,["user_id"=>$v]);
        }
        if($res1){
            response(0,"批量通过成功");
        }else{
            response(-1,"批量通过失败");
        }
    }

    /**
     * 批量不通过
     */
    public function no_pass_all(){
        $ids=$_POST['ids'];
        if(empty($ids)){
            response(-1,"请选择要批量操作的数据");
        }
        foreach ($ids as $k=>$v){
            $data['test_user_autograph']="";
            $data['is_status']=1;
            $data['update_time']=date("Y-m-d H:i:s",time());
            $res1=$this->table->update("users",$data,["user_id"=>$v]);
        }
        if($res1){
            response(0,"批量不通过成功");
        }else{
            response(-1,"批量不通过失败");
        }
    }

    /**
     * 添加马甲
     */
    public function add_mj(){
        $data=[];
        $data[0]=[
            "uuid"=>Tools::UUID(),
            "third_uuid"=>"host_".Tools::UUID(),
            "nick_name"=>"春晚",
            "nick_pic"=>"https://s-js.sports.cctv.com/host/image/2019/01/10/15471029483793.png",
            "user_type"=>2,
            "add_time"=>date("Y-m-d H:i:s"),
        ];
        $data[1]=[
            "uuid"=>Tools::UUID(),
            "third_uuid"=>"host_".Tools::UUID(),
            "nick_name"=>"网络春晚",
            "nick_pic"=>"https://s-js.sports.cctv.com/host/image/2019/01/10/15471029689670.png",
            "user_type"=>2,
            "add_time"=>date("Y-m-d H:i:s"),
        ];
        $data[2]=[
            "uuid"=>Tools::UUID(),
            "third_uuid"=>"host_".Tools::UUID(),
            "nick_name"=>"炫舞未来",
            "nick_pic"=>"https://s-js.sports.cctv.com/host/image/2019/01/10/15471029925918.png",
            "user_type"=>2,
            "add_time"=>date("Y-m-d H:i:s"),
        ];
        $data[3]=[
            "uuid"=>Tools::UUID(),
            "third_uuid"=>"host_".Tools::UUID(),
            "nick_name"=>"央视网",
            "nick_pic"=>"https://s-js.sports.cctv.com/host/image/2019/01/10/15471030158969.jpg",
            "user_type"=>2,
            "add_time"=>date("Y-m-d H:i:s"),
        ];
        $data[4]=[
            "uuid"=>Tools::UUID(),
            "third_uuid"=>"host_".Tools::UUID(),
            "nick_name"=>"央视影音",
            "nick_pic"=>"https://s-js.sports.cctv.com/host/image/2019/01/10/15471030388557.jpg",
            "user_type"=>2,
            "add_time"=>date("Y-m-d H:i:s"),
        ];
        $len=count($data);
//        foreach($data as $k=>$v){
//            $this->table->add("users",$v);
//            if($k+1==$len){
//                response(0,"添加成功");
//            }
//        }
    }
}